<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎注册牛逼书屋</view>
			<input class="u-border-bottom" type="text" v-model="userName" placeholder="请输入用户昵称" />
			<input class="u-border-bottom" type="text" v-model="email" placeholder="请输入邮箱" />
			<input class="u-border-bottom" type="password" v-model="password" placeholder="请输入密码" />
			<input class="u-border-bottom" type="password" v-model="rePassword" placeholder=" 输入确认密码" />
			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">注册</button>
		
		</view>
	</view>	
</template>

<script>
	export default {
		data() {
			return {
				userName:"",
				email:"",
				password:"",
				rePassword:""
			}
		},
		methods: {
			submit(){
				if(!this.userName||!this.email||!this.password||!this.rePassword) {
					this.$u.toast("信息不能为空")
					return
				}
				if(!this.$u.test.email(this.email)){
					this.$u.toast("邮箱填写错误")
					return
				}
				if(this.userName.length<6){
					this.$u.toast("用户名不能小于六位数")
					return
				}
				if(this.password !== this.rePassword){
					this.$u.toast("确认密码不一致")
					return
				}
				//发送注册请求
				this.$u.api.authRegister({
					name:this.userName,
					email:this.email,
					password:this.password,
					password_confirmation:this.rePassword
				}).then(res =>{
					if(!this.vuex_token){
						//返回登录页
						this.$u.toast("注册成功，请登录")
						setTimeout(()=>{
							this.$u.route({
								type:"redirect",
								url:"pages/auth/login"
							})
						},1500)
					}
				})

				
			}
		},
		computed:{
			inputStyle() {
				let style = {};
				if(this.userName&&this.email&&this.password&&this.rePassword) {
					style.color = "#fff";
					style.backgroundColor = this.$u.color['warning'];
				}
				return style;
			}
		}
	}
</script>

<style lang="scss" scoped>
.u-border-bottom{
	padding: 20rpx !important;
	margin-bottom: 20rpx !important;
}	
.wrap {
	font-size: 28rpx;
	.content {
		width: 600rpx;
		margin: 80rpx auto 0;

		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.tips {
			color: $u-type-info;
			margin-bottom: 60rpx;
			margin-top: 8rpx;
		}
		.getCaptcha {
			background-color: rgb(253, 243, 208);
			color: $u-tips-color;
			border: none;
			font-size: 30rpx;
			padding: 12rpx 0;
			
			&::after {
				border: none;
			}
		}
		.alternative {
			color: $u-tips-color;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}

}
</style>
